package base.template;

/**
 * @program: DesignPatterns
 * @description: 实现对个字符串打印
 * @author: Mr.Dai
 * @create: 2018-04-28 16:18
 **/
public class StringDisplay extends AbstractDisplay {
    private String string;
    private int width;

    public StringDisplay(String string) {
        this.string = string;
        this.width = string.getBytes().length;
    }

    @Override
    public void open() {
        printline();
    }

    private void printline() {
        System.out.print("+");
        for (int i = 0; i < width; i++) {
            System.out.print("-");
        }
        System.out.println("+");
    }
    @Override
    public void print() {
        System.out.println("|"+string+"|");
    }

    @Override
    public void close() {
        printline();
    }

    @Override
    public void display() {
        super.display();
    }
}
